import java.util.Scanner;

public class Demo9 {
    private static boolean running = true;

    public static void main(String[] args) {
         Thread t = new Thread(() -> {
             while (running) {
                 System.out.println("hello thread");
                 try {
                     Thread.sleep(10000);
                 } catch (InterruptedException e) {
                     throw new RuntimeException(e);
                 }
             }
             System.out.println("thread 结束");
         });

        t.start();

        // 在 main 方法中, 让用户通过进行输入, 触发 t 线程的终止
        Scanner scanner = new Scanner(System.in);
        System.out.println("输入任意内容, 控制 t 线程结束: ");
        scanner.next();   // 使用这个方法, main 就会阻塞!
        running = false;
    }
}
